package com.beiding.workordersystem.orders.looporder.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.beiding.workordersystem.main.utils.Json;
import com.beiding.workordersystem.orders.looporder.model.ExpirationDayConfig;
import com.beiding.workordersystem.orders.product.entity.Product;
import com.beiding.workordersystem.system.entity.UserEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
@Setter
@TableName("loop_order")
public class LoopOrder {

    @TableId
    private String id;

    //终止合作原因
    private String endCooperationReason;

    private Boolean companyToDeal = false;

    //负责人id
    private String principalId;

    //主主管,通过申请的主管具有该权限
    private String mainSatrapId;

    //业务员id
    private String creatorId;

    private Integer status;

    private String refuseReason;

    private String companyId;

    @TableField(exist = false)
    private List<OrderProduct> products;

    public ExpirationDayConfig getExpirationDayConfigEntity() {
        return Json.parse(expirationDayConfig, ExpirationDayConfig.class);
    }

    /*
       被激活的税种及周期
       格式为  税种-周期码   周期码 0 月报 ,1  季报; 多个规则使用","进行分隔

       例如:
            A税种-0,B税种-1

     */
    private String activeTaxCategoriesAndCycle;

    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    //服务开始时间
    private Date serviceStartTime;

    //服务结束时间

    //使用结束时间和当前时间进行比对判断是否到期
    private Date serviceEndTime;

    private String service;

    @TableField(exist = false)
    private String statusName;

    @TableField(exist = false)
    private List<LoopProcess> processes;

    @TableField(exist = false)
    private UserEntity creator;

    private String expirationDayConfig;


    @TableField(exist = false)
    private Company company;

    //服务费用
    private Double fee;

    private static Map<Integer, String> statusMap = new HashMap<>();

    static {
        statusMap.put(0, "新增");
        statusMap.put(1, "退回");
        statusMap.put(2, "待审核");
        statusMap.put(3, "待指派");
        statusMap.put(4, "未开始");
        statusMap.put(5, "进行中");
        statusMap.put(6, "服务到期");
        statusMap.put(7, "终止合作");
        statusMap.put(8, "过期");   //可以执行退回操作
    }

    public void setStatus(Integer status) {
        this.status = status;
        this.statusName = statusMap.get(status);
    }
}
